﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GalaSoft.MvvmLight;
using NtpChat.Client.Model;
using System.Windows.Data;
using System.Windows.Media;


namespace NtpChat.Client.ViewModel
{
    public class UserViewModel: ViewModelBase
    {

        public UserViewModel(User user)
        {
            this.user = user;
        }


        private User user;

        public User User
        {
            get { return user; }
        }
        public const string UserNamePropertyName = "UserName";
        public String UserName
        {
            get
            {
                return user.UserName;
            }

            set
            {
                if (user.UserName == value)
                {
                    return;
                }

                var oldValue = user.UserName;
                user.UserName = value;
                RaisePropertyChanged(UserNamePropertyName);

            }
        }


        public const string StatusPropertyName = "Status";
        public UserStatus Status
        {
            get
            {
                return user.Status;
            }

            set
            {
                if (user.Status == value)
                {
                    return;
                }

                var oldValue = user.Status;
                user.Status = value;
                RaisePropertyChanged(StatusPropertyName);

            }
        }
    }

    public class ColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            UserStatus status = (UserStatus)value;

            if (status == UserStatus.Online)
                return Color.FromRgb(29, 206, 20);
            if (status == UserStatus.Busy)
                return Color.FromRgb(202, 93, 93);

            return Color.FromRgb(29, 206, 20);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value;
        }
    }

}
